﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace BizAppFactory.Domain
{
    public partial class DomainClass
    {
        public List<Role> Roles
        {
            get 
            {
                List<Role> roles = new List<Role>();
                string roleName;

                foreach (Association assoc in Association.GetLinksToTargetClasses(this))
                {
                    roleName = (String.IsNullOrEmpty(assoc.TargetRoleName) ?
                                        assoc.TargetDomainClass.Name :
                                        assoc.TargetRoleName);
                    roles.Add(new Role()
                    {
                        Name = roleName,
                        Multiplicity = assoc.TargetMultiplicity,
                        DomainClass = assoc.TargetDomainClass,
                        PeerRoleName = assoc.SourceRoleName,
                        PeerRoleMultiplicity = assoc.SourceMultiplicity,
                        RoleType = RoleType.Target,
                        Association =assoc
                    });
                }

                foreach (Association assoc in Association.GetLinksToSourceClasses(this))
                {
                    roleName = (String.IsNullOrEmpty(assoc.SourceRoleName) ? 
                                        assoc.SourceDomainClass.Name : 
                                        assoc.SourceRoleName);

                    roles.Add(new Role() 
                    { 
                        Name = roleName, 
                        Multiplicity = assoc.SourceMultiplicity,
                        DomainClass = assoc.SourceDomainClass,
                        PeerRoleName = assoc.TargetRoleName, 
                        PeerRoleMultiplicity = assoc.TargetMultiplicity,
                        RoleType = RoleType.Source,
                        Association = assoc
                    });   

                }

                return roles;
            }
        }
    }
}
